<?php
session_start ();
// 判断用户是否已经登录
if (! isset ( $_SESSION ["userinfo"] ) and empty ( $_SESSION ["userinfo"] ["userid"] )) {
	header ( "location:../index.php" );
	session_unset ();
	session_destroy ();
	exit ();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="zh-CN">
<link href="./Resource/Style/base.yy.css" rel="stylesheet"
	type="text/css">
<link href="./Resource/Style/info.yy.css" rel="stylesheet"
	type="text/css">
</head>
<body>
<?php
require_once '../tools/SqlHelper.class.php';
if (isset ( $_POST ['user_submit'] ) and $_POST ['user_submit'] == '保存') {
	// 获取浏览器发过来的页面数据
	$pc_address = $_POST ['s_province'] . " " . $_POST ['s_city'] . " " . $_POST ['s_county'];
	$ps_apartment_str = preg_split ( "/[\s,]+/", $pc_address );
	$pc_min_age = $_POST ['con_age_min'];
	$pc_max_age = $_POST ['con_age_max'];
	$pc_education = $_POST ['con_edu'];
	$pc_min_height = $_POST ['con_height_min'];
	$pc_max_height = $_POST ['con_height_max'];
	$pc_income = $_POST ['con_income'];
	$user_id = $_SESSION ["userinfo"] ["userid"];
	// $user_id = "xufeng520";
	$sql = "UPDATE `personals_condition_tb` SET `pc_address`='$pc_address', `pc_min_age`=$pc_min_age, `pc_min_height`=$pc_min_height,`pc_max_height`=$pc_max_height, `pc_education`=$pc_education, `pc_income`=$pc_income, `pc_max_age`=$pc_max_age WHERE `user_id`='$user_id'";
	// 创建一个SqlHelper对象
	$sqlHelper = new SqlHelper ();
	$res = $sqlHelper->execute_dql ( $sql );
	if (! $res) {
		echo "<script>alert('保存征友条件失败')</script>";
	} else {
		echo "<script>alert('保存征友条件成功')</script>";
	}
	// 资源
	// mysql_free_result ( $res );
	$sqlHelper->close_connect ();
} else {
	$user_id = $_SESSION ["userinfo"] ["userid"];
	// $user_id = "xufeng520";
	$sql = "select * from `personals_condition_tb` where `user_id`='$user_id'";
	// 创建一个SqlHelper对象
	$sqlHelper = new SqlHelper ();
	$row = $sqlHelper->execute_dql ( $sql );
	$res = mysql_fetch_array ( $row );
	// 关闭连接
	$pc_address = $res ['pc_address'];
	if ($pc_address == "0") {
		$pc_address = "省份 地级市 市、县级市";
	}
	$ps_apartment_str = preg_split ( "/[\s,]+/", $pc_address );
	$pc_min_age = $res ['pc_min_age'];
	$pc_max_age = $res ['pc_max_age'];
	$pc_education = $res ['pc_education'];
	$pc_min_height = $res ['pc_min_height'];
	$pc_max_height = $res ['pc_max_height'];
	$pc_income = $res ['pc_income'];
	mysql_free_result ( $row );
	$sqlHelper->close_connect ();
}
?>
	<nav>
		<div class="info_nav">
			<ul>
				<li><a href="./baseData.php">基本资料</a></li>
				<li><a href="./Details.php">详细资料</a></li>
				<li><a href="./soliloquy.php">内心独白</a></li>
				<li><a href="./uploadingPhoto.php">上传头像</a></li>
				<li><a href="./myPhoto.php">我的相册</a></li>
				<li><a class="a_out" href="#">征友条件</a></li>
				<li><a href="./changePassword.php">修改密码</a></li>
			</ul>
		</div>
	</nav>
	<form action="./PersonalCondition.php" method="post">
		<div class="info_con">
			<ol class="lonely">
				<li><label>希望对方居住地：</label> <select id="s_province"
					name="s_province"></select> <select id="s_city" name="s_city"></select>
					<select id="s_county" name="s_county"></select> <script
						class="resources library" src="./Resource/Style/area.js"
						type="text/javascript"></script> <script type="text/javascript">_init_area(<?php echo "'$ps_apartment_str[0]','$ps_apartment_str[1]','$ps_apartment_str[2]'";?>);</script></li>
				<li><label>希望对方年龄：</label> <select id="sel_age_min"
					name="con_age_min">
						<?php
						if ($pc_min_age == "0") {
							echo "<option class='selectList value='0' selected='selected'>不限制</option>";
						} else {
							echo "<option class='selectList value='0'>不限制</option>";
						}
						for($i = 18; $i < 50; $i ++) {
							if ($i == ( int ) $pc_min_age) {
								echo "<option class='selectList' value='" . $i . "' selected='true'>" . $i . "岁</option>";
							} else {
								echo "<option class='selectList' value='" . $i . "'>" . $i . "岁</option>";
							}
						}
						?>
				</select> <span>到</span> <select id="sel_age_max" name="con_age_max">
						<?php
						if ($pc_max_age == "0") {
							echo "<option class='selectList value='0' selected='selected'>不限制</option>";
						} else {
							echo "<option class='selectList value='0'>不限制</option>";
						}
						for($i = 18; $i < 50; $i ++) {
							if ($i == ( int ) $pc_max_age) {
								echo "<option class='selectList' value='" . $i . "' selected='true'>" . $i . "岁</option>";
							} else {
								echo "<option class='selectList' value='" . $i . "'>" . $i . "岁</option>";
							}
						}
						?>
				</select></li>
				<li><label>希望对方身高：</label> <select id="sel_height_min"
					name="con_height_min">
					<?php
					if ($pc_min_height == "0") {
						echo "<option class='selectList value='0' selected='selected'>不限制</option>";
					} else {
						echo "<option class='selectList value='0'>不限制</option>";
					}
					for($i = 140; $i < 200; $i += 5) {
						if ($i == ( int ) $pc_min_height) {
							echo "<option class='selectList' value='" . $i . "' selected='true'>" . $i . "厘米</option>";
						} else {
							echo "<option class='selectList' value='" . $i . "'>" . $i . "厘米</option>";
						}
					}
					?>
				</select> <span>到</span> <select id="sel_height_max"
					name="con_height_max">
						<?php
						if ($pc_max_height == "0") {
							echo "<option class='selectList value='0' selected='selected'>不限制</option>";
						} else {
							echo "<option class='selectList value='0'>不限制</option>";
						}
						for($i = 140; $i < 200; $i += 5) {
							if ($i == ( int ) $pc_max_height) {
								echo "<option class='selectList' value='" . $i . "' selected='true'>" . $i . "厘米</option>";
							} else {
								echo "<option class='selectList' value='" . $i . "'>" . $i . "厘米</option>";
							}
						}
						?>
				</select></li>
				<li><label>希望对方学历：</label> <select id="sel_con_edu" name="con_edu">
						<option value="0" selected="selected"
							<?php if($pc_education == "0"){echo "selected='true'";}?>>不限制</option>
						<option class="selectList" value="5"
							<?php if($pc_education == "5"){echo "selected='true'";}?>>初中及以下</option>
						<option class="selectList" value="1"
							<?php if($pc_education == "1"){echo "selected='true'";}?>>高中及中专</option>
						<option class="selectList" value="2"
							<?php if($pc_education == "2"){echo "selected='true'";}?>>大专</option>
						<option class="selectList" value="3"
							<?php if($pc_education == "3"){echo "selected='true'";}?>>本科</option>
						<option class="selectList" value="4"
							<?php if($pc_education == "4"){echo "selected='true'";}?>>硕士及以上</option>
				</select></li>
				<li><label>希望对方收入：</label> <select id="sel_con_income"
					name="con_income">
						<option value="0" selected="selected"
							<?php if($pc_income == "0"){echo "selected='true'";}?>>不限制</option>
						<option class="selectList" value="3"
							<?php if($pc_income == "3"){echo "selected='true'";}?>>小于2000</option>
						<option class="selectList" value="4"
							<?php if($pc_income == "4"){echo "selected='true'";}?>>2000-5000</option>
						<option class="selectList" value="5"
							<?php if($pc_income == "5"){echo "selected='true'";}?>>5000-10000</option>
						<option class="selectList" value="6"
							<?php if($pc_income == "6"){echo "selected='true'";}?>>10000-20000</option>
						<option class="selectList" value="7"
							<?php if($pc_income == "7"){echo "selected='true'";}?>>20000以上</option>
				</select> <span>/月</span></li>
			</ol>
			<div class="keep">
				<input type="submit" name="user_submit" value="保存" />
			</div>
		</div>
	</form>
</body>
</html>